<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    a {
      /* position: relative; */
      display: block;
      width: 50px;
      margin: 50px 100px;
    }

    #msg {
      position: absolute;
      display: none;
      width: 400px;
      height: 150px;
      background-color: skyblue;
    }
  </style>
</head>
<body>
  <a href="#">唐太宗</a>
  <a href="#">唐高宗</a>
  <a href="#">武则天</a>
  <a href="#">唐玄宗</a>
  <div id="msg"></div>
  <script>
    // 1、onmouseover：鼠标经过，信息显示
    // 2、onmouseout：鼠标移出，信息隐藏
    // 3、onmousemove：信息跟随鼠标移动
    var aAs = document.getElementsByTagName("a")
    var oMsg = document.getElementById("msg")
    var text = ["1", "2", "3", "4"]
    for (var i = 0; i < aAs.length; i++) {
      aAs[i].index = i

      aAs[i].onmouseover = function() {
        oMsg.style.display = "block"
        oMsg.innerHTML = text[this.index]
      }

      aAs[i].onmouseout = function() {
        oMsg.style.display = "none"
      }

      aAs[i].onmousemove = function(ev) {
        var e = ev || window.event
        oMsg.style.left = e.clientX + 15 + "px"
        oMsg.style.top = e.clientY + 10 + "px"
      }
    }
  </script>
</body>
</html>